<?php
include_once("connect.php");
include_once ("log_order.php"); //test!

//-----------------------------
//---include 
require( '../wp-load.php' );
//---get user_id
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;
//---check if login
if ( !is_user_logged_in() || $user_id<1 ) { 
	$url = wp_login_url("index.php");
	echo "<script language='javascript' type='text/javascript'>";  
	echo "parent.location.href='$url'";  
	echo "</script>"; 
	exit;
} 
//-----------------------------
//$user_id = 1; //test! ???

$id=$_GET['id'];

$order_id = 0;
$shipper = '';
$address_id1 = 0;
$address_id2 = 0;
if(!empty($id) && $id>0){
	$sql = "SELECT * FROM order_list WHERE id=$id";
	$rs = mysql_query($sql);
	if ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
		$order_id = $row['id'];
		$shipper = $row['shipper'];
		$user_id = $row['order_user_id'];
		//$upadate_time = $row['update_time'];		
		$address_id1 = $row['address_from_id'];
		$address_id2 = $row['address_to_id'];
	}
}


$add1=$_GET['add1'];
$add2=$_GET['add2'];
if(!empty($add1) && $add1>0){	
	$address_id1 = $add1;
}
if(!empty($add2) && $add2>0){	
	$address_id2 = $add2;
}
	
	
$idc_name1 = '';	
$country1 = '德国';
$city1 = '';
$address1 = '';
$postcode1 = ''; 
$tel1 = '';
$email1 = '';
$door_num1 = '';
if($address_id1>0){	
	$sql = "SELECT * FROM order_address WHERE order_user_id=$user_id AND id=$address_id1";	
	$rs = mysql_query($sql);
	if ($row1 = mysql_fetch_array($rs, MYSQL_ASSOC)) {		
		$idc_name1 = $row1['idc_name'];
		$country1 = $row1['country'];
		$city1 = $row1['city'];
		$address1 = $row1['address'];
		$postcode1 = $row1['postcode'];
		$tel1 = $row1['tel'];
		$email1 = $row1['email'];
		$door_num1 = $row1['door_num'];		
	} 
}

$idc_name2 = '';	
$country2 = '中国大陆';
$province2 = '';
$city2 = '';
$address2 = '';
$postcode2 = ''; 
$tel2 = '';
$email2 = '';
if($address_id2>0){	
	$sql = "SELECT * FROM order_address WHERE order_user_id=$user_id AND id=$address_id2";	
	$rs = mysql_query($sql);
	if ($row2 = mysql_fetch_array($rs, MYSQL_ASSOC)) {		
		$idc_name2 = $row2['idc_name'];
		$country2 = $row2['country'];
		$province2 = $row2['province'];
		$city2 = $row2['city'];
		$address2 = $row2['address'];
		$postcode2 = $row2['postcode'];
		$tel2 = $row2['tel'];
		$email2 = $row2['email'];				
	} 	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="hello" />
<meta name="description" content="Hello" />
<title>order_user_show</title>

<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/fancybox.css" />

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.fancybox.js" type="text/javascript"></script>
<script src="js/jquery.message.js" type="text/javascript"></script>


<style type="text/css">
table{width:100%; margin:20px auto; border-collapse:collapse;}
table td{line-height:24px; padding:2px; padding-left:8px; border:1px solid #b6d6e6;}
.table_title{height:26px; line-height:26px; background:url(css/btn_bg.gif) repeat-x bottom; font-weight:bold; text-indent:.3em; outline:0;}
.table_label2{background:#e8f5fe; text-align:center; font-weight:bold;}
.table_label{background:#e8f5fe; text-align:right; }

.table_line{ text-align:center; font-weight:bold;}

.btn{height:24px; background:url(css/btn_bg.gif) repeat-x; padding:0 4px; font-size:12px; border:1px solid #ccc; cursor:pointer; margin-left:3px}
.input{border:1px solid #369; background:#ffc; padding:2px}
.msg{padding-left:30px; margin-top:20px}
textarea{font-size:12px}
</style>

<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">
$(function(){
	$('#add_form').ajaxForm({
		beforeSubmit: validate,
		success: function(msg){				
			if(msg > '0'){	
				$().message("成功");	
				<?php 
				  if($order_id > 0){
					echo "self.location='order_list.php';"; 
				  }else{
					echo "var tmp_id=msg;  self.location='order_item.php?id='+tmp_id;"; 
				  }
				?>	
			}else{
				alert(msg);
			}
		}
	});


	$("#cancle_btn").click(function(){
		//window.history.back(-1); 
		self.location='order_list.php';
	});
	
	$("#save_addr_btn").click(function(){
		self.location='order_save_addr.php?id=<?php echo $order_id; ?>';
	});

});
function validate(formData, jqForm, options) {  
    for (var i=0; i < formData.length; i++) { 
        if (!formData[i].value) { 
			$().message("请输入完整相关信息");
            return false; 
        } 
    } 
	$().message("正在提交...");
}
</script>
</head>

<body>

<div id="main">

<form id="add_form" action="order_do_address.php?action=add" method="post">
  
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <thead>
    <tr class="table_title">
      <td colspan="6"><?php 
	  if($order_id > 0){
		echo "修改-订单号:".$order_id; 
	  }else{
		echo "新增订单"; 
	  }
	  ?></td>
    </tr>
  </thead>
  <tbody>
	<tr>
      <td class="table_line" id="shipper" colspan="6" alight=center>物流商：
			<select name="shipper">
				<option value="DHL" <?php if ($shipper=='DHL') echo 'selected'; ?>>DHL</option>
				<option value="EMS" <?php if ($shipper=='EMS') echo 'selected'; ?>>EMS</option>
			</select>
	  </td>
    </tr> 
  
	<tr>
      <td class="table_label2"  colspan="3" width="50%">&nbsp;寄件人信息</td>
	  <td class="table_label2"  colspan="3" width="50%">&nbsp;收件人信息</td>
    </tr>
	<tr>
		<td colspan="3">	  
			请使用德文填写寄件信息
			<br>  
		</td>
		<td colspan="3">请使用中文填写收件信息
		</td>
    </tr> 
	
    <tr>
      <td class="table_label" width="10%">寄件人：</td>
      <td class="edit" id="idc_name1" width="40%" colspan="2">
		<input type="text" class="input2" name="idc_name1" maxlength="60" value="<?php echo $idc_name1; ?>" />
	  </td>
	  
	  <td class="table_label" width="10%">收件人：</td>
      <td class="edit" id="idc_name2" width="40%" colspan="2">
		<input type="text" class="input2" name="idc_name2" maxlength="60" value="<?php echo $idc_name2; ?>" />
	  </td>
    </tr>
	
	<tr>
      <td class="table_label" >国家/地区：</td>
      <td class="edit" colspan="2"><select name="country1">
					<option value="德国" <?php if ($country1=='德国') echo 'selected'; ?>>德国</option>
					<option value="荷兰" <?php if ($country1=='荷兰') echo 'selected'; ?>>荷兰</option>
					<option value="中国大陆" <?php if ($country1=='中国大陆') echo 'selected'; ?>>中国大陆</option>
					<option value="香港" <?php if ($country1=='香港') echo 'selected'; ?>>香港</option>
					<option value="澳门" <?php if ($country1=='澳门') echo 'selected'; ?>>澳门</option>
					<option value="台湾" <?php if ($country1=='台湾') echo 'selected'; ?>>台湾</option>                
				</select>
		</td>	  
	  <td class="table_label" >国家/地区：</td>
      <td class="edit" colspan="2"><select name="country2">
					<option value="德国" <?php if ($country2=='德国') echo 'selected'; ?>>德国</option>
					<option value="荷兰" <?php if ($country2=='荷兰') echo 'selected'; ?>>荷兰</option>
					<option value="中国大陆" <?php if ($country2=='中国大陆') echo 'selected'; ?>>中国大陆</option>
					<option value="香港" <?php if ($country2=='香港') echo 'selected'; ?>>香港</option>
					<option value="澳门" <?php if ($country2=='澳门') echo 'selected'; ?>>澳门</option>
					<option value="台湾" <?php if ($country2=='台湾') echo 'selected'; ?>>台湾</option>               
				</select>
		</td>
    </tr>	
	
	<tr>
      <td class="table_label" >城市：</td>
      <td class="edit"  colspan="2">
		<input type="text" class="input2" name="city1" maxlength="60" value="<?php echo $city1; ?>" />
	  </td>	  
	  <td class="table_label" >省份：</td>
      <td class="edit" colspan="2">
		<input type="text" class="input2" name="province2" maxlength="60" value="<?php echo $province2; ?>" />
	  </td>	  
    </tr>
	
	<tr>
      <td class="table_label" >门牌号：</td>
      <td class="edit" colspan="2">
		<input type="text" class="input2" name="door_num1" maxlength="60" value="<?php echo $door_num1; ?>" />
	  </td>	  
	  <td class="table_label" >城市：</td>
      <td class="edit"  colspan="2">
		<input type="text" class="input2" name="city2" maxlength="60" value="<?php echo $city2; ?>" />
	  </td>	
    </tr>
	
	<tr>
      <td class="table_label" >地址：</td>
      <td class="edit" colspan="2">
		<textarea type="text" class="input3" name="address1" rows="2" cols="44"><?php echo $address1; ?></textarea>
	  </td>	  
	  <td class="table_label" >地址：</td>
      <td class="edit" colspan="2">
		<textarea type="text" class="input3" name="address2" rows="2" cols="44"><?php echo $address2; ?></textarea>
	  </td>	
    </tr>
	
	<tr>
      <td class="table_label" >邮编：</td>
      <td class="edit" colspan="2">
		<input type="text" class="input2" name="postcode1" maxlength="60" value="<?php echo $postcode1; ?>" />
	  </td>	  
	  <td class="table_label" >邮编：</td>
      <td class="edit" colspan="2">
		<input type="text class="input2" name="postcode2" maxlength="60" value="<?php echo $postcode2; ?>" />
	  </td>	
    </tr>

	<tr>
      <td class="table_label" >联系电话：</td>
      <td class="edit" colspan="2">
		<input type="text" class="input2" name="tel1" maxlength="60" value="<?php echo $tel1; ?>" />
	  </td>	  
	  <td class="table_label" >联系电话：</td>
      <td class="edit" colspan="2">
		<input type="text" class="input2" name="tel2" maxlength="60" value="<?php echo $tel2; ?>" />
	  </td>	
    </tr>

	<tr>
      <td class="table_label" >联系email：</td>
      <td class="edit" colspan="2">
		<input required type="email" class="input2" name="email1" maxlength="60" value="<?php echo $email1; ?>" />
	  </td>	  
	  <td class="table_label" >联系email：</td>
      <td class="edit" colspan="2">
		<input required type="email" class="input2" name="email2" maxlength="60" value="<?php echo $email2; ?>" />
	  </td>
    </tr>

	<!--
	<tr>
		<td colspan="3">
			<input type="checkbox" class="checkbox" name="save1" value="1" />
			保存为常用寄件地址（超过20个将替换最早地址）
		</td>
		<td colspan="3">
			<input type="checkbox" class="checkbox" name="save2" value="1" />
			保存为常用收件地址（超过20个将替换最早地址）
		</td>
    </tr> 	
	-->

	<tr>
      <td class="table_line"  colspan="6" alight=center>
		&nbsp; &nbsp;
	  </td>
    </tr> 
	  
	  
	<tr>
      <td class="table_line"  colspan="6" alight=center>
	  <input type="hidden" class="input2" name="user_id"  value="<?php echo $user_id; ?>" />
	  <input type="hidden" class="input2" name="order_id"  value="<?php echo $order_id; ?>" />
	  
	  <input type="submit" class="btn" value="提 交"/>	 &nbsp; &nbsp; 
	  <input type="button" class="btn" id="cancle_btn" value="返 回" /> &nbsp; &nbsp;
	  <input type="button" class="btn" id="save_addr_btn" value="常用地址" /> &nbsp; &nbsp;
	  </td>
    </tr> 
	
  </tbody>
</table>

</form>
<br/>


</div>

</body>
</html>